﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using KBWebApi.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KBWebApi.Controllers
{
    /// <summary>
    /// 维护生产状态信息
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class WorkStatusController : ControllerBase
    {
        Bll.WorkStatusBll workStatusBll = new Bll.WorkStatusBll();

        /// <summary>
        /// 获取全部数据列表(分页查询)
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetAllList")]
        public async Task<ActionResult> GetAllList()
        {
            var result = await workStatusBll.GetAllList();
            return new JsonResult(
                new
                {
                    code = 20000,
                    message = result
                }
            );
        }

        /// <summary>
        /// 新增或修改生产状态数据
        /// </summary>
        /// <param name="workStatus"></param>
        /// <returns></returns>
        [HttpPost]
        //[WabApiAuthorize]
        [Route("NewOrUpdate")]
        public async Task<ActionResult> NewOrUpdate(WorkStatusModel workStatus)
        {
            if (workStatus == null)
            {
                return new JsonResult(new
                {
                    code = 20001,
                    message = "失败"
                });
            }

            var result = await workStatusBll.NewOrUpdate(workStatus);
            return result;
        }

        /// <summary>
        /// 根据ID删除生产状态数据
        /// </summary>
        /// <param name="WorkStatusId"></param>
        /// <returns></returns>
        [HttpGet]
        //[WabApiAuthorize]
        [Route("Delete")]
        public async Task<ActionResult> Delete(string WorkStatusId)
        {
            if (string.IsNullOrEmpty(WorkStatusId))
            {
                return new JsonResult(new
                {
                    code = 20001,
                    message = "失败"
                });
            }

            var result = await workStatusBll.Delete(WorkStatusId);
            return result;
        }
    }
}